<script setup>
import { storeToRefs } from 'pinia'
import { computed, ref, watch } from 'vue'
import FlightList from './FlightList.vue'
import Video from './Video.vue'
import { usePopStore } from '@/stores'
import { addRadar } from '@/views/infrastructure/js/infrastructure'
import { useFlyNumStore } from '@/stores/modules/flynum'
const popStore = usePopStore()
const { Equipment, XY } = storeToRefs(popStore)
const close = () => {
  Equipment.value.showPop = false
  __g.customObject.delete('co1')
  __g.marker.showByGroupId('equipment')
  __g.marker.deleteByGroupId('equipmentMakerRadar')
  __g.weather.setCloudThickness(2)
  flyNumStore.setRadioShow(false)
  flyNumStore.setShowUi(false)
}

const dialogPosition = ref([0, 0])
watch(
  Equipment.value,
  (newVal) => {
    if (newVal) {
      dialogPosition.value = XY.value
    }
  },
  {
    deep: true
  }
)

const showFlight = ref(false)
const flightList = ref(null)
const lookFlight = () => {
  showFlight.value = !showFlight.value
  if (showFlight.value) {
    flightList.value.setData(Equipment.value.popInfo.flightActivities)
  } else {
    flightList.value.close()
  }
}
const type = [
  { index: 1, type: '监视' },
  { index: 2, type: '通信' },
  { index: 3, type: '导航' }
]
const showVideo = ref(false)
const video = ref(null)
const loolVideo = () => {
  showVideo.value = !showVideo.value
  if (showVideo.value) {
    video.value.setData(Equipment.value.popInfo.videoUrl)
  } else {
    video.value.close()
  }
}

const flyNumStore = useFlyNumStore()
const showRadio = ref(false)
watch(
  () => flyNumStore.radioShow,
  (newVal) => {
    showRadio.value = newVal
  },
  { deep: true, immediate: true }
)
</script>
<template>
  <transition
    appear
    name="custom-classes-transition"
    enter-active-class="animate__animated  animate__fadeIn"
    leave-active-class="animate__animated animate__faster  animate__fadeOut"
  >
    <div
      class="AirspacePop"
      ref="currentDom"
      :style="{
        left: dialogPosition[0] > 0 ? dialogPosition[0] + 'px' : 'unset',
        top: dialogPosition[1] + 'px'
      }"
      v-if="Equipment.showPop"
    >
      <p class="title">
        <span>设备信息</span>
        <span @click="close"><img src="@img/pop/close_icon.png" alt="" /></span>
      </p>
      <div class="content">
        <div class="left">
          <p>
            <span>· <i>设备名称</i> ：</span>
            <el-tooltip effect="dark" :content="Equipment.popInfo.deployName" placement="top">
              <span>{{ Equipment.popInfo.deployName }}</span>
            </el-tooltip>
          </p>
          <p>
            <span>· <i>设备类型</i> ：</span>
            <el-tooltip effect="dark" :content="Equipment.popInfo.deployType" placement="top">
              <span>{{ Equipment.popInfo.deployType }}</span>
            </el-tooltip>
          </p>
          <p>
            <span>· <i>建设单位</i>：</span>
            <el-tooltip effect="dark" :content="Equipment.popInfo.companyName" placement="top">
              <span>{{ Equipment.popInfo.companyName }}</span>
            </el-tooltip>
          </p>
          <p>
            <span>· <i>覆盖范围</i>：</span>
            <el-tooltip effect="dark" :content="Equipment.popInfo.coverage" placement="top">
              <span>{{ Equipment.popInfo.coverage }} M</span>
            </el-tooltip>
          </p>
          <p>
            <span>· <i>分类</i>：</span>
            <!-- <span>{{ type.find((item) => item.index === Equipment.popInfo.type)?.type }}</span> -->
            <span>{{ Equipment.popInfo.type }}</span>
          </p>
        </div>
        <div class="right">
          <p class="top">
            <span @click="loolVideo" :class="{ active: showVideo }">视频监控</span>
            <!-- <span @click="addRadar()" :class="{ active: showVideo }" v-if="showRadio"
              >查看详情</span
            > -->
          </p>
          <p class="bottom">
            <img v-if="Equipment.popInfo.photo" :src="Equipment.popInfo.photo" alt="" />
            <img v-else src="@img/pop/img.png" alt="" />
          </p>
        </div>
      </div>
    </div>
  </transition>
  <FlightList ref="flightList" @closeFlight="showFlight = false" />
  <Video ref="video" @closeVideo="showVideo = false" />
</template>

<style scoped lang="scss">
.AirspacePop {
  position: fixed;
  z-index: 9;
  top: 110px;
  right: 400px;
  width: 400px;
  background: url('@img/pop/airspace_bg.png');
  background-size: 100% 100%;

  .title {
    display: flex;
    padding: 10px 20px 10px 50px;
    align-items: center;
    font-size: 16px;
    justify-content: space-between;

    span:last-child {
      width: 18px;
      height: 18px;
      cursor: pointer;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .content {
    margin-top: 5px;
    padding: 12px;
    display: flex;
    font-size: 13px;

    .left {
      flex: 1;

      p {
        display: flex;
        margin-bottom: 10px;

        span:first-child {
          flex: 0 0 92px;
          color: #afebff;
          display: flex;
          align-items: center;

          i {
            display: inline-block;
            width: 100%;
            margin: 0 3px;
            text-align-last: justify;
            text-align: justify;
            font-style: normal;
          }
        }

        span:last-child {
          flex: 1;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        &.name {
          font-size: 14px;
        }
      }
    }

    .right {
      flex: 0 0 150px;
      margin-left: 5px;

      .top {
        display: flex;
        align-self: center;
        justify-content: space-between;
        font-size: 13px;

        span {
          width: 70px;
          height: 37px;
          line-height: 37px;
          text-align: center;
          background: url('@img/pop/btn_bg.png');
          background-size: 100% 100%;
          cursor: pointer;

          &.active {
            background: url('@img/pop/btn_active.png');
            background-size: 100% 100%;
          }
        }
      }

      .bottom {
        margin-top: 10px;

        img {
          width: 100%;
        }
      }
    }
  }
}
</style>
